using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using Spacejock;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Threading;
using yW5Lib;

namespace yWriter6
{
	public class clsPrintScenesPerItem
	{
		public delegate void PrintProgressEventHandler(string ProgressString);

		[CompilerGenerated]
		private PrintProgressEventHandler PrintProgressEvent;

		public event PrintProgressEventHandler PrintProgress
		{
			[CompilerGenerated]
			add
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Combine(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Remove(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
		}

		public void PrintScenesPerItem(clsProject cProject)
		{
			//Discarded unreachable code: IL_0260, IL_0277, IL_0282, IL_0292, IL_033c, IL_033e, IL_0352, IL_0374
			int num = default(int);
			int num4 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				clsShared.cSubs.BusyMouse();
				num2 = 3;
				clsReport clsReport = new clsReport(ref clsShared.cLog, ref clsShared.cSettings, "Scenes per Item");
				num2 = 4;
				clsReport.AddTitle();
				num2 = 5;
				clsReport.AddCentered(cProject.Title + " by " + cProject.AuthorName);
				num2 = 6;
				clsReport.AddBR(2);
				num2 = 7;
				clsReport.SetTableBorder(1);
				num2 = 8;
				clsReport.OpenTable("cellpadding=5");
				num2 = 9;
				clsCollection<int> clsCollection = cProject.SceneIDsInOrder(cProject.AllChapters(), WithUnused: false);
				num2 = 10;
				IEnumerator enumerator = cProject.Items.GetEnumerator();
				while (enumerator.MoveNext())
				{
					clsItem clsItem = (clsItem)enumerator.Current;
					num2 = 11;
					int num3 = 0;
					num2 = 12;
					clsReport.OpenRow();
					num2 = 13;
					clsReport.AddCell(clsReport.Bold(clsItem.Title), "colspan=2 align=left");
					num2 = 14;
					clsReport.CloseRow();
					num2 = 15;
					IEnumerator enumerator2 = clsCollection.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						int iD = Conversions.ToInteger(enumerator2.Current);
						num2 = 16;
						clsScene clsScene = cProject.get_SceneByID(iD);
						num2 = 17;
						if (clsScene.ContainsItemID(clsItem.ID))
						{
							num2 = 18;
							clsChapter clsChapter = cProject.get_ChapterByID(clsScene.BelongsToChID);
							num2 = 19;
							num3++;
							num2 = 20;
							clsReport.OpenRow();
							num2 = 21;
							clsReport.AddCell(Conversions.ToString(num3));
							num2 = 22;
							clsReport.AddCell("(" + clsChapter.Title + ") " + clsScene.Title);
							num2 = 23;
							clsReport.CloseRow();
						}
						num2 = 24;
					}
					num2 = 25;
					if (enumerator2 is IDisposable)
					{
						(enumerator2 as IDisposable).Dispose();
					}
					num2 = 26;
					clsReport.OpenRow();
					num2 = 27;
					clsReport.AddCell("Appears in " + Conversions.ToString(num3) + " scene(s)", "colspan=2 align=left");
					num2 = 28;
					clsReport.CloseRow();
					num2 = 29;
				}
				num2 = 30;
				if (enumerator is IDisposable)
				{
					(enumerator as IDisposable).Dispose();
				}
				num2 = 31;
				clsReport.CloseTable();
				num2 = 32;
				clsReport.AddFooter(App.Title);
				num2 = 33;
				clsReport.Show();
				num2 = 34;
				PrintProgressEvent?.Invoke("Printing Complete");
				num2 = 35;
				clsShared.cSubs.NormalMouse();
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num4 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0372: Could not find block for branch target IL_033e*/;
			}
			if (num4 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
